const mongoose = require('mongoose');
const bcryptjs = require('bcryptjs');
const Schema = mongoose.Schema;
const user = new Schema({
    name: String,
    token: String,
    athour: String,
    age: Number,
    email: String,
    role: String,
    status: String,
},{ timestamps: { createdAt: 'created', index: true } }); //自更新

const deviceInfo = new Schema({
    push: Number,
})
const device = new Schema({
    deviceName: String,
    info: deviceInfo,
    author: {type: Schema.Types.ObjectId, ref:"user"}, 
});

const account = new Schema({
    accout: {
        type: String,
        minLength: 6,
        maxLength: 18,
        required: [true, 'User phone number required']
    },
    password: {
        type:String,
        required: [true, 'passwored required']
    },
    user_id:{
        type: Schema.Types.ObjectId, ref: 'User',
        required: true,
    }
},{
    timestamps: { createdAt: 'createdAt', index: true },
});

const mySchema = new Schema({
    uid: {type: String, index: true}, //uid
    size: {type: Number}, //文件大小(字节)
    buffer: {type: Buffer}, //数据
}, {timestamps: {createdAt: 'created', index: true}});

const User = mongoose.model('User', user);
const Device = mongoose.model('Device', device);
const Account = mongoose.model('Accout', account);
const DeviceInfo = mongoose.model('deviceInfo', deviceInfo);
module.exports = { User, Device, Account, DeviceInfo, mySchema };